import isNumber from './isNumber'
import { equals, divide } from 'ramda'
export default function round(value: number, len = 2) {
	if (len > 0) {
		if (isNumber(value)) {
			return get(value, len)
		}
		const _value = Number(value)
		if (isNaN(_value)) {
			return _value
		} else {
			return get(value, len)
		}
	} else {
		return value
	}
}

function get(value: number, len = 2) {
	let _len = '1'
	for (let i = 0; i < len; i++) {
		_len = _len + '0'
	}

	if (equals(value, 0)) {
		return 0
	} else {
		return divide(Math.round(value * Number(_len)), Number(_len))
	}
}
